<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--院系评价-->
      <!-- <el-col :span="4" :xs="5">
        <treeIndex :deptOptions="deptOptions" @handleNode="handleNodeClick" :title="'部门信息'"></treeIndex>
      </el-col> -->
      <el-col :span="24" :xs="24">
        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />

        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="examinemonadList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="学年" align="center" prop="amcYear" />
          <el-table-column label="批次名称" align="center" prop="batchName" />
          <!-- <el-table-column label="考核体系类型" align="center" prop="ceeName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clr_exam_systype" :value="scope.row.ceeName" />
        </template>
          </el-table-column>-->
          <el-table-column label="辅导员教工号" align="center" prop="clrTno" />
          <el-table-column label="辅导员姓名" align="center" prop="clrName" />
          <el-table-column label="所在院系" align="center" prop="deptName" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <!-- <router-link :to="'/examinemonad/mark/index/' + scope.row" class="link-type">
            <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['clr:examinemonad:edit']"
          >查看详情</el-button>
              </router-link>-->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['clr:examinescoring:openscoring']"
              >打分</el-button>
              <!-- <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['clr:examinescoring:openscoring']"
              >打分</el-button> -->
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { deptlist, getExaminemonad } from "@/api/clr/examinemonad";
import searchForm from "@/components/Search/searchForm.vue";
import { deptTreeSelect } from "@/api/system/user";
// import treeIndex from "@/components/tree/index.vue";
import { getSelector} from "@/api/clr/batch";
import {
  collegeSelect
} from "@/api/information/studentInfor"

export default {
  name: "Examinemonad",
  dicts: ["clr_exam_systype"],
  components: {
    // treeIndex,
    searchForm
  },
  data() {
    return {
      formLabelWidth: "90px",
      formOptions: [
        {
          label: "院系",
          prop: "deptId",
          element: "el-select",
          options: [],
          placeholder: "请选择院系"
        },
        {
          label: "辅导员工号",
          prop: "clrTno",
          element: "el-input",
          placeholder: "请输入辅导员工号"
        },
        {
          label: "辅导员姓名",
          prop: "clrName",
          element: "el-input",
          placeholder: "请输入辅导员姓名"
        },
        {
          label: "批次名称",
          prop: "cebId",
          element: "el-select",
          options: [],
          placeholder: "请输入批次名称"
        },
        {
          label: "学年",
          prop: "amcYears",
          type: "monthrange",
          element: "el-date-picker",
          placeholder: "请选择学年",
          valueFormat: 'yyyy-MM'
        },
       
      ],
      deptOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅导员考核人员表格数据
      examinemonadList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cebId: null,
        cId: null,
        clrTno: null,
        clrName: null
      }
    };
  },
  watch: {
    $route (to, from) {
      console.log(to, from)
      // this.渲染数据的函数()
      // this.queryParams = this.$route.params
      this.getList();
    }
  },
  created() {
    this.getList();
    this.department();
    getSelector({cebType:'A'}).then(res => {
      console.log(res,'kaoje')
      this.formOptions[3].options = res.data.map(item => {
        return {
          value: item["CEBID"],
          label: item["BATCHNAME"]
        };
      });
    })
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      if(val.amcYears) {
        val.startAmcYear = val.amcYears[0];
        val.endAmcYear = val.amcYears[1];
      }
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      data.startAmcYear = undefined
      data.endAmcYear = undefined
      this.queryParams.pageNum = 1;
      this.queryParams.deptId = '';
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    // 获取部门信息
    async department() {
      await collegeSelect().then(res => {
        // this.deptOptions = res.data;
        this.formOptions[0].options = res.data.map(item => {
          return {
            value: item.deptId,
            label: item.deptName
          };
        });
      });
    },
    /** 查询辅导员考核人员列表 */
    getList() {
      this.loading = true;
      deptlist(this.queryParams).then(response => {
        this.examinemonadList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // tree树形选中的值
    handleNodeClick(data) {
      // console.log(data.label, "选中的值");
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cemId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加辅导员考核人员";
    },
    /** 打分 */
    handleUpdate(row) {
      getExaminemonad(row.cemId).then(response => {
        this.$router.push({ name: "Mark", params: response.data });
        this.form = response.data;
        // this.open = true;
        this.title = "修改辅导员考核人员";
      });
    }
  }
};
</script>
